package com.stormrage.entity.ent;

import java.io.Serializable;
import java.util.Date;

import com.stormragetech.core.exception.StormrageTechException;
import com.stormragetech.core.util.SecureUtil;

/**
 * @Title: EntAcct.java
 * @Package com.stormrage.entity.ent
 * @Description: 企业用户 Entity 类
 * @author www.stormragetech.com
 * @date 2016年4月10日
 * @version V1.0
 */
public class EntAcct implements Serializable {

	// ------------------------------- Fields -------------------------------

	private static final long serialVersionUID = 211216551429188915L;

	// ------------------------------- Fields -------------------------------

	private Integer id; // 编号

	private String acct; // 用户名

	private String pass; // 密码

	private String salt; // 盐

	private Integer entId;

	private String realName; // 真实姓名

	private Date regDate;

	private Integer locked;

	// ------------------------------- Fields -------------------------------

	public EntAcct() {
	}

	// ------------------------------- Fields -------------------------------

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getAcct() {
		return acct;
	}

	public void setAcct(String acct) {
		this.acct = acct;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public Integer getEntId() {
		return entId;
	}

	public void setEntId(Integer entId) {
		this.entId = entId;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public Integer getLocked() {
		return locked;
	}

	public void setLocked(Integer locked) {
		this.locked = locked;
	}

	public String getSign() {
		return acct + salt;
	}

	// ------------------------------- Fields -------------------------------

	public static EntAcct instance(EntAcct entity) throws StormrageTechException {
		entity.setSalt(SecureUtil.initUUID());
		entity.setPass(SecureUtil.initPass("123456", entity.getSign()));
		return entity;
	}

	@Override
	public String toString() {
		return this.getClass() + " : id - " + id + " acct - " + acct + " pass - " + pass + " salt - " + salt
				+ " entId - " + entId + " realName - " + realName + " regDate - " + regDate + " locked - " + locked;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		EntAcct acct = (EntAcct) o;

		if (id != null ? !id.equals(acct.id) : acct.id != null)
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

}
